using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using System.Windows;
using System.Windows.Data;
using Ricciolo.PaperBoy.Feeds;

namespace Ricciolo.PaperBoy.UI.Converters
{
    public class FeedToSettingsConverter : IValueConverter
    {
        private MainWindow _mainWindow;

        public FeedToSettingsConverter(MainWindow mainWindow)
        {
            _mainWindow = mainWindow;
        }

        #region IValueConverter Members

        object IValueConverter.Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            FeedSetting fs;
            if (value is IFeed)
                if (_mainWindow.FeedSettings.TryGetValue(((IFeed)value).Path, out fs))
                {
                    if (parameter == null)
                        return fs;
                    else
                        switch (parameter.ToString())
                        {
                            case "IsExpanded":
                                return fs.IsExpanded;
                            case "Zoom":
                                return fs.Zoom;
                            case "ViewingMode":
                                return fs.ViewingMode;
                        }
                }

            return DependencyProperty.UnsetValue;
        }

        object IValueConverter.ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
